package requests

import (
	"github.com/gin-gonic/gin"
	"github.com/thedevsaddam/govalidator"
	"wskyygyso/api/app/requests/validators"
)

type ResetPasswordByPhoneRequest struct {
	Phone      string `json:"phone" valid:"phone"`
	PassWord   string `json:"pass_word" valid:"pass_word"`
	VerifyCode string `json:"verify_code" valid:"verify_code"`
}

func ResetPassWordByPhone(data interface{}, c *gin.Context) map[string][]string {
	rules := govalidator.MapData{
		"phone": []string{
			"required", "digits:11",
		},
		"verify_code": []string{
			"required", "digits:6",
		},
		"pass_word": []string{
			"required", "min:6",
		},
	}

	messages := govalidator.MapData{
		"phone": []string{
			"required:手机号为必填项，参数名称 phone",
			"digits:手机号长度必须为 11 位的数字",
		},
		"verify_code": []string{
			"required:验证码答案必填",
			"digits:验证码长度必须为 6 位的数字",
		},
		"pass_word": []string{
			"required:密码为必填项",
			"min:密码长度需大于 6",
		},
	}

	errs := validate(data, rules, messages)
	_data := data.(*ResetPasswordByPhoneRequest)
	errs = validators.ValidateVerifyCode(_data.Phone, _data.VerifyCode, errs)
	return errs
}

type ResetPassWordByEmailRequest struct {
	Email      string `json:"email" valid:"email"`
	VerifyCode string `json:"verify_code" valid:"verify_code"`
	PassWord   string `json:"pass_word" valid:"pass_word"`
}

func ResetPassWordByEmail(data interface{}, c *gin.Context) map[string][]string {
	rules := govalidator.MapData{
		"email": []string{
			"required", "email", "min:3",
		},
		"pass_word": []string{
			"required", "min:6",
		},
		"verify_code": []string{
			"required", "digits:6",
		},
	}
	messages := govalidator.MapData{
		"email": []string{
			"required:必须设置邮箱",
			"email:必须是邮箱格式",
			"min:邮箱长度必须大于3",
		},
		"verify_code": []string{
			"required:验证码答案必填",
			"digits:验证码长度必须为 6 位的数字",
		},
		"pass_word": []string{
			"required:密码为必填项",
			"min:密码长度需大于 6",
		},
	}
	errs := validate(data, rules, messages)
	_data := data.(*ResetPassWordByEmailRequest)
	errs = validators.ValidateVerifyCode(_data.Email, _data.VerifyCode, errs)
	return errs
}
